package com.lyn.solitude.pluginhost.factory

import android.content.res.Resources
import com.lyn.solitude.pluginhost.PluginManager
import com.lyn.solitude.pluginhost.binder.PluginHostBinder
import com.lyn.solitude.pluginhost.resources.CreateResourceBloc
import java.util.concurrent.ConcurrentSkipListMap

/**
 *
 * @author longyn 2024/05/23
 * @version 1.0.0
 */
object ResourcesFactory {

    @JvmStatic
    private val map: MutableMap<String, Resources> = ConcurrentSkipListMap()

    @JvmStatic
    fun get(path: String): Resources? {
        try {
            if (map.containsKey(path)) {
                return map[path]
            }
            val resources = CreateResourceBloc.create(path, PluginHostBinder.application)
            map[path] = resources
            return resources
        } catch (e: Throwable) {
            e.printStackTrace()
        }
        return null
    }

    @JvmStatic
    fun remove(path: String) {
        try {
            map.remove(path)
        } catch (e: Throwable) {
            e.printStackTrace()
        }
    }
}